package com.xxx.video.dynamic.adapters;


import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.dbs.beans.SearchFriendHistoryBean;
import com.xxx.video.commen.utils.ListUtils;
import com.xxx.video.commen.views.TagAdapter;
import com.xxx.video.commen.views.TagLayout;
import com.xxx.video.mine.adapters.SearchFriendHistoryListAdapter;

import java.util.List;

import butterknife.BindView;

public class FindFriendRecommendAdapter extends BaseRecycleViewAdapter<SearchFriendHistoryBean, FindFriendRecommendAdapter.MyHolder> {
    /**
     * search history list
     */
    private List<SearchFriendHistoryBean> searchHistoryBeanList;

    public FindFriendRecommendAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_find_friend_recommend;
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    @Override
    public boolean isSetBaseItemViewClickListener() {
        return false;
    }

    /**
     * set search history list
     *
     * @param searchHistoryBeanList data
     */
    public void setSearchHistoryListData(List<SearchFriendHistoryBean> searchHistoryBeanList) {
        this.searchHistoryBeanList = searchHistoryBeanList;
        notifyDataSetChanged();
    }

    class MyHolder extends BaseViewHolder {

        @BindView(R.id.tv_item_search_recommend_list_history_tile)
        TextView tvItemSearchRecommendListHistoryTile;
        @BindView(R.id.tv_item_search_recommend_list_history_clear)
        TextView tvItemSearchRecommendListHistoryClear;
        @BindView(R.id.tl_item_search_recommend_list_history_list)
        TagLayout tlItemSearchRecommendListHistoryList;
        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            if (ListUtils.isEmpty(searchHistoryBeanList)) {
                return;
            }
            SearchFriendHistoryListAdapter searchFriendHistoryListAdapter = new SearchFriendHistoryListAdapter(searchHistoryBeanList);
            tlItemSearchRecommendListHistoryList.setAdapter(searchFriendHistoryListAdapter);
            searchFriendHistoryListAdapter.setOnItemClickListener((TagAdapter.OnItemClickListener<SearchFriendHistoryBean>) (searchHistoryBean, position1, type) -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(searchHistoryBean, position, 3);
                }
            });
            tvItemSearchRecommendListHistoryClear.setOnClickListener(v -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(null, position, 4);
                }
            });
        }
    }
}
